﻿@page "/Admin/VisLogs"
@attribute [Authorize]
@attribute [TabItemOption(Text ="访问日志",Icon ="fa fa-th")]
@inherits BasePage
@inject ISysVisLogService SysVisLogService

<div class="overflow-hidden h-100">
    <Table TItem="VisLogOutput"
            @ref = "@_table"
            IsPagination="true"
            IsStriped="true"
            IsMultipleSelect="true"
            IsBordered="true"
            IsFixedHeader="true" 
            AllowResizing="true"
            ShowLoading="true"
            ShowColumnList="true"
            ShowCardView="true"
            ShowToolbar="true"
            ShowDefaultButtons="false"
            ShowSearch="true"
            ShowEmpty="true" 
            SearchModel="@_search" 
            SearchMode="SearchMode.Top"
            PageItemsSource="@(new int[] { 15, 50 })"
            OnQueryAsync="@OnQueryAsync">
        <TableColumns>
            <TableColumn @bind-Field="@context.Name" />
            <TableColumn @bind-Field="@context.VisType" />
            <TableColumn @bind-Field="@context.Success" />
            <TableColumn @bind-Field="@context.Ip" />
            <TableColumn @bind-Field="@context.Browser" />
            <TableColumn @bind-Field="@context.VisTime" Width="180" FormatString="yyyy-MM-dd HH:mm:ss"/>
            <TableColumn @bind-Field="@context.Account" />
        </TableColumns>
        <TableToolbarTemplate>
            <TableToolbarButton TItem="VisLogOutput" Text="清空日志" IsAsync />
        </TableToolbarTemplate>
        <SearchTemplate>
            <GroupBox Title="搜索条件">
                <div class="row g-3 form-inline">
                    <div class="col-4">
                        <BootstrapInput @bind-Value="@context.Name" ShowLabel="true"/>
                    </div>
                </div>
            </GroupBox>
        </SearchTemplate>
    </Table>
</div>


@code{
    private Table<VisLogOutput>? _table;
    private VisLogOutput _search = new();

    private Task<QueryData<VisLogOutput>> OnQueryAsync(QueryPageOptions options)
        => SysVisLogService.PageAsync(_search.Adapt<VisLogPageInput>(options));
}